//
//  Model_user.m
//  KWNClient
//
//  Created by 张明磊 on 14-10-16.
//  Copyright (c) 2014年 张明磊. All rights reserved.
//

#import "Model_user.h"

static Model_user *appConsole = nil;

#undef   KWNPhone
#define  KWNPhone   @"useName"

#undef   KWNUserToken
#define  KWNUserToken   @"userToken"

#undef   KWNUserID
#define  KWNUserID   @"useId"

#undef   KWNDeviceToken
#define  KWNDeviceToken   @"deviceToken"

#undef   KWNUnReadCount
#define  KWNUnReadCount   @"unReadCount"

#undef   KWNLaywerLevel
#define  KWNLaywerLevel   @"laywerLevel"

#undef   KWNLaywerIsUp
#define  KWNLaywerIsUp   @"LaywerIsUp"

#undef   KWNLaywerFirst
#define  KWNLaywerFirst   @"LaywerFirst"

#undef   KWNLaywerEver
#define  KWNLaywerEver   @"LaywerEver"

@implementation Model_user

+ (Model_user *)sharedInstance{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        appConsole = [[self alloc] init];
    });
    return appConsole;
}

#pragma mark - 获取用户token -
/**
 *  获取用户token
 */
- (NSString *)getToken{
    NSString *string_token = [[NSUserDefaults standardUserDefaults] objectForKey:KWNUserToken];
    return string_token;
}

#pragma mark - 获取用户姓名 -
/**
 *  获取用户姓名
 */
- (NSString *)getUserName{
    NSString *string_token = [self getToken];
    if(string_token){
        NSString *string_phone = [[NSUserDefaults standardUserDefaults] objectForKey:KWNPhone];
        return string_phone;
    }
    else{
        return nil;
    }
}

#pragma mark - 获取电话用于显示-
/**
 *  获取电话用于显示
 */
- (NSString *)getUserPhone{
    NSString *string_phone = [[NSUserDefaults standardUserDefaults] objectForKey:KWNPhone];
    return string_phone;
}

#pragma mark - 获取用户ID-
/**
 *  获取用户ID
 */
- (NSString *)getUserID;{
    NSString *string_phone = [[NSUserDefaults standardUserDefaults] objectForKey:KWNUserID];
    return string_phone;
}

#pragma mark - 获取设备id-
/**
 *  获取设备id
 */
- (NSString *)getDeviceToken{
    NSString *string_phone = [[NSUserDefaults standardUserDefaults] objectForKey:KWNDeviceToken];
    return string_phone;
}

#pragma mark - 设置用户姓名 -
/**
 *  设置用户姓名
 */
- (void)setUID:(NSString *)string_id{
    [[NSUserDefaults standardUserDefaults] setObject:string_id forKey:KWNUserID];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

#pragma mark - 设置用户token -
/**
 * 设置用户token
 */
- (void)setToken:(NSString *)string_token{
    [[NSUserDefaults standardUserDefaults] setObject:string_token forKey:KWNUserToken];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

#pragma mark - 设置电话用于显示-
/**
 *  设置电话用于显示
 */
- (void)setUserPhone:(NSString *)string_phone{
    [[NSUserDefaults standardUserDefaults] setObject:string_phone forKey:KWNPhone];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

#pragma mark - 设置设备token-
/**
 *  设置设备token
 */
- (void)setDeviceToken:(NSString *)string_dToken{
    [[NSUserDefaults standardUserDefaults] setObject:string_dToken forKey:KWNDeviceToken];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

#pragma mark - 用户退出登录-
/**
 *  用户退出登录
 */
- (void)loginOut{
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:KWNUserToken];
    [[NSUserDefaults standardUserDefaults] synchronize];
    NSString *string_token = [self getToken];
    if(string_token){
        [[NSUserDefaults standardUserDefaults] setObject:nil forKey:KWNUserToken];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
}

#pragma mark - 存储未读条数 -
/**
 *  存储未读条数
 */
- (void)setUnReadCount:(NSString *)string_count{
    [[NSUserDefaults standardUserDefaults] setObject:string_count forKey:KWNUnReadCount];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

#pragma mark - 获取未读条数 -
/**
 *  获取未读条数
 */
- (NSString *)getUnReadCount{
    NSString *string_count = [[NSUserDefaults standardUserDefaults] objectForKey:KWNUnReadCount];
    NSString *string_token = [self getToken];
    if(string_count && string_token){
        return string_count;
    }
    else{
        return @"0";
    }
}

#pragma mark - 设置律师等级 -
/**
 *  设置律师等级
 */
- (void)setLaywerLevelWith:(NSString *)level{
    NSString *string_level = [[NSUserDefaults standardUserDefaults] objectForKey:KWNLaywerLevel];
    if([string_level isEqualToString:level] || [level isEqualToString:@"1"]){
        [self setLayerIsUp:NO];
    }
    else{
        [self setLayerIsUp:YES];
    }
    [[NSUserDefaults standardUserDefaults] setObject:level forKey:KWNLaywerLevel];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

#pragma mark - 判断律师是否升级 -
/**
 *  判断律师是否升级
 */
- (void)setLayerIsUp:(BOOL)isUp{
    if(isUp){
        [[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:KWNLaywerIsUp];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
    else{
        [[NSUserDefaults standardUserDefaults] setObject:@"NO" forKey:KWNLaywerIsUp];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
}

- (BOOL)getLayerIsUp{
    NSString *string_bool = [[NSUserDefaults standardUserDefaults] objectForKey:KWNLaywerIsUp];
    if([string_bool isEqualToString:@"YES"]){
        return YES;
    }
    else{
        return NO;
    }
}

/*#pragma mark - 判断是否第一次进入律师页 -
 
- (BOOL)isFirstLaywer{
    if (![[NSUserDefaults standardUserDefaults] boolForKey:KWNLaywerEver]) {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:KWNLaywerEver];
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:KWNLaywerFirst];
    }
    else{
        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:KWNLaywerFirst];
    }
    return [[NSUserDefaults standardUserDefaults] boolForKey:KWNLaywerFirst];
}*/

@end
